package cn.fl.project.controller;

import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.mid.core.framework.page.Pager;
import cn.fl.project.service.IVehicleStyleService;
import cvm.store.facade.cvm.condition.VechileStyleQC;
import cvm.store.facade.cvm.dto.VechileStyleDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 车型库挂车
 * 作者:hongyanbo
 * 时间:2018/8/11
 */
@Controller
@RequestMapping("/vehicle/trailer")
public class TrailerVehicleStyleController {

    @Autowired
    private IVehicleStyleService vehicleStyleService;

    /**
     * to list page
     * @param modelAndView
     * @param prjId
     * @return
     */
    @RequestMapping("trailerList.do")
    public ModelAndView trailerList(ModelAndView modelAndView ,String prjId, HttpServletRequest request){
        modelAndView.addObject("prjId",prjId);
        modelAndView.setViewName("project/vehicle/trailerList");
        String prjPrdChangeFlag = request.getParameter("prjPrdChangeFlag");
        String oldDtlId = request.getParameter("oldDtlId");
        //启用支付表信息
        String paySchId = request.getParameter("paySchId");
        String paySchNo = request.getParameter("paySchNo");
        modelAndView.addObject("prjPrdChangeFlag",prjPrdChangeFlag);
        modelAndView.addObject("oldDtlId",oldDtlId);
        modelAndView.addObject("paySchId",paySchId);
        modelAndView.addObject("paySchNo",paySchNo);
        return modelAndView;
    }

    /**
     * to list page
     * @param modelAndView
     * @param prjId
     * @return
     */
    @RequestMapping("trailerListRoute.do")
    public ModelAndView trailerListRoute(ModelAndView modelAndView , String prjId, HttpServletRequest request){
        String prdId = request.getParameter("prdId");
        String insRoutePrdId = request.getParameter("insRoutePrdId");
        modelAndView.addObject("prjId",prjId);
        modelAndView.addObject("prdId",prdId);
        modelAndView.addObject("insRoutePrdId",insRoutePrdId);
        modelAndView.setViewName("project/vehicle/trailerListRoute");
        return modelAndView;
    }

    /**
     * 初始化list数据
     * @param page
     * @param pagesize
     * @param condition
     * @return
     */
    @RequestMapping("initList.do")
    @ResponseBody
    public Object initList(int page, int pagesize, VechileStyleQC condition){
        Pager pager = new Pager();
        pager.setCurrentPage(page);
        pager.setEveryPage(pagesize);
        pager.setCondition(condition);
        condition.setIsTrailerSelect(true);
        condition.setStyleStatus(1L); //车型状态为启用的
        pager = vehicleStyleService.selectTrailerListPage(pager);
        List<VechileStyleDTO> resultList = (List<VechileStyleDTO>) pager.getResultList();

        ListPageVO<VechileStyleDTO> listPage = new ListPageVO<VechileStyleDTO>(resultList, pager.getTotalCount());
        return listPage;
    }
    /**
     * 厂商查询列表初始化
     * 所有车型库中有车型数据的厂商
     * @return
     */
    @RequestMapping("/mfrList.do")
    @ResponseBody
    public List<KeyValueVO> mfrList(){
        List<KeyValueVO> mfrList = vehicleStyleService.getMfrList();
        return mfrList;
    }

    /**
     * 用途查询列表初始化
     * 所有挂车车辆用途
     * @return
     */
    @RequestMapping("trailerUsageList.do")
    @ResponseBody
    public List<KeyValueVO> trailerUsageList(){
        List<KeyValueVO> trailerUsageList = vehicleStyleService.getTrailerUsageList();
        return trailerUsageList;
    }
}
